import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { NoteCate } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/addCate",
  method: "post",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      let cate = await new NoteCate(r.payload);
      await cate.save();
      return { code: 200, data: true, message: "添加成功" };
    } catch (err: any) {
      return err;
    }
  },
  options: {
    payload: {
      parse: true, // 解析请求体
      allow: "application/json", // 允许JSON格式的请求体
    },
    plugins: {
      "hapi-swagger": {
        security: [{ apiKey: [] }],
      },
    },
    tags: ["api"],
  },
};
export default route;
